import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Stack;
//https://leetcode.cn/problems/implement-queue-using-stacks/submissions/555468288/
class MyQueue {

    Deque<Integer> stackOffer;
    Deque<Integer> stackPoll;

    public MyQueue() {
        stackOffer = new ArrayDeque<>();
        stackPoll = new ArrayDeque<>();
    }
    
    public void push(int x) {
        stackOffer.push(x);
    }
    
    public int pop() {
        if (stackPoll.isEmpty()) {
            while (!stackOffer.isEmpty()) {
                stackPoll.push(stackOffer.pop());
            }
        }
            return stackPoll.pop();
    }
    
    public int peek() {
        if (stackPoll.isEmpty()) {
            while (!stackOffer.isEmpty()) {
                stackPoll.push(stackOffer.pop());
            }
        }
            return stackPoll.peek();
    }
    
    public boolean empty() {
        return stackPoll.isEmpty() && stackOffer.isEmpty();
    }
}